﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace kpi.KpiForm_uManager
{
    public partial class KpiForm : System.Web.UI.Page
    {
        static String SelectedMonth = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            Label_UserName.Text = User.Identity.Name;
            //Label_DebugMsg.Visible = false;

            if (!Page.IsPostBack)
            {
                DropdownList_ShowUserNames();
                DropDownList_SelectMonth_AddItems();
            }

            if ((!User.IsInRole("User")) & (!User.IsInRole("u_manager")))
            {
                Label_UserGuide.Text = "<br />";
                Label_UserGuide.Text += "<fieldset>";
                Label_UserGuide.Text += "<legend>说明</legend>";
                Label_UserGuide.Text += "<ol>";
                Label_UserGuide.Text += "<li>新用户首次使用该系统，首先应当注册用户账户；已经注册账户的用户，请进行登录。</li>";
                Label_UserGuide.Text += "<li>系统中的账户只分为“管理者账户”和“一般账户”两种，区别是“管理者账户”可以对所管理的“一般账户”进行查看和评分。</li>";
                Label_UserGuide.Text += "<li>所有账户注册完成即为“一般账户”，“管理者账户”需要系统管理员进行<a href=\"Account/UserRolesMgr.aspx\">人工指定</a>。</li>";
                Label_UserGuide.Text += "</ol>";
                Label_UserGuide.Text += "</fieldset>";
                Label_UserGuide.Visible = true;
            }
            else if (User.IsInRole("User"))
            {
                //Label_NavigationLink.Text = "<br />";
                //Label_NavigationLink.Text += "<ul>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_user/KpiForm.aspx\">录入并确认我的KPI信息</a></li>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_user/KpiFormUserRec.aspx\">对我的KPI信息进行自评分</a></li>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_user/ShowKpiInfo.aspx\">查看我的KPI考评得分</a></li>";
                //Label_NavigationLink.Text += "</ul>";
                //Label_NavigationLink.Visible = true;

                Label_UserGuide.Text = "<br />";
                Label_UserGuide.Text += "<fieldset>";
                Label_UserGuide.Text += "<legend>说明</legend>";
                Label_UserGuide.Text += "<ol>";
                Label_UserGuide.Text += "<li>您已作为“一般账户”登录。</li>";
                Label_UserGuide.Text += "<li>您可以录入自己的KPI信息，对KPI信息进行自评分，查看自己的KPI信息。</li>";
                Label_UserGuide.Text += "<li>您不能查看或管理下级用户。</li>";
                Label_UserGuide.Text += "<li>您不能查看或管理其他用户的KPI信息。</li>";
                Label_UserGuide.Text += "</ol>";
                Label_UserGuide.Text += "</fieldset>";
                Label_UserGuide.Visible = true;
            }
            else if (User.IsInRole("u_manager"))
            {
                //Label_NavigationLink.Text = "<br />";
                //Label_NavigationLink.Text += "<ul>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_user/KpiForm.aspx\">录入并确认我的KPI信息</a></li>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_user/KpiFormUserRec.aspx\">对我的KPI信息进行自评分</a></li>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_user/ShowKpiInfo.aspx\">查看我的KPI考评得分</a></li>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_uManager/KpiFormUserMgr.aspx\">管理我的下级用户</a></li>";
                //Label_NavigationLink.Text += "<li><a href=\"KpiForm_uManager/KpiForm.aspx\">管理下级KPI信息</a></li>";
                //Label_NavigationLink.Text += "</ul>";
                //Label_NavigationLink.Visible = true;

                Label_UserGuide.Text = "<br />";
                Label_UserGuide.Text += "<fieldset>";
                Label_UserGuide.Text += "<legend>说明</legend>";
                Label_UserGuide.Text += "<ol>";
                Label_UserGuide.Text += "<li>您已作为“管理者账户”登录。</li>";
                Label_UserGuide.Text += "<li>默认显示的是用户已确认完成情况的KPI信息。</li>";
                Label_UserGuide.Text += "<li>您可以查看全部或者单一下级的KPI信息。</li>";
                Label_UserGuide.Text += "<li>您还可以对下级用户的KPI信息进行考评。</li>";
                Label_UserGuide.Text += "<li>您只能对下级用户的上月KPI信息进行考评。</li>";
                Label_UserGuide.Text += "</ol>";
                Label_UserGuide.Text += "</fieldset>";
                Label_UserGuide.Visible = true;
            }
        }

        protected void DropDownList_SelectMonth_AddItems()
        {
            SqlConnection SqlConnection = new SqlConnection("Data Source=192.168.0.241;Initial Catalog=kpi_forms_db;Persist Security Info=True;User ID=sa;Password=My.SA");
            SqlConnection.Open();

            //SqlCommand selectCommand = new SqlCommand("SELECT DISTINCT CONVERT(nvarchar, YEAR(u_kpi_conf_datetime))+'-'+ CONVERT(nvarchar, MONTH(u_kpi_conf_datetime)) FROM [dbo].[u_kpi_table] WHERE u_kpi_conf_datetime IS NOT NULL", SqlConnection);
            SqlCommand SelectCommand = new SqlCommand("SELECT DISTINCT CONVERT(nvarchar, YEAR(u_kpi_conf_datetime))+'-0'+ CONVERT(nvarchar, MONTH(u_kpi_conf_datetime)) AS YearMonth FROM [dbo].[u_kpi_table] WHERE u_kpi_conf_datetime IS NOT NULL ORDER BY YearMonth DESC", SqlConnection);

            SqlDataReader YearMonthReader = SelectCommand.ExecuteReader();

            while (YearMonthReader.Read())
            {
                DropDownList_SelectMonth.Items.Add(new ListItem(YearMonthReader["YearMonth"].ToString(), YearMonthReader["YearMonth"].ToString() + "-01"));
                //DropDownList_SelectMonth.Items.Add(new ListItem(YearMonthReader[0].ToString(), YearMonthReader[1].ToString()));
            }

            //处理无满足条件
            if (YearMonthReader.HasRows)
            {
                //Label_HisInfoMsg.Visible = true;
                DropDownList_SelectMonth.Visible = true;
                //Button_ShowHisInfo.Visible = true;
            }
            else
            {
                //Label_HisInfoMsg.Visible = false;
                DropDownList_SelectMonth.Visible = false;
                //Button_ShowHisInfo.Visible = false;
            }

            YearMonthReader.Dispose();
            YearMonthReader.Close();
            SelectCommand.Dispose();
            SqlConnection.Close();
        }

        protected void DropdownList_ShowUserNames()
        {
            DropDownList_UserName.Dispose();
            DropDownList_UserName.Items.Add(new ListItem("全部", "all"));

            SqlConnection SqlConnection = new SqlConnection("Data Source=192.168.0.241;Initial Catalog=kpi_forms_db;Persist Security Info=True;User ID=sa;Password=My.SA");
            SqlConnection.Open();

            String selectCommand = "SELECT DISTINCT UserName FROM [dbo].[u_kpi_table] WHERE UserName IN ( SELECT UserName FROM [u_kpi_userInManager] WHERE uManagerName='" + User.Identity.Name + "') ORDER BY UserName";
            SqlCommand SelectCommand = new SqlCommand(selectCommand, SqlConnection);
            SqlDataReader RoleNameReader = SelectCommand.ExecuteReader();

            while (RoleNameReader.Read())
            {
                DropDownList_UserName.Items.Add(new ListItem(RoleNameReader["UserName"].ToString(), RoleNameReader["UserName"].ToString()));
            }

            SqlConnection.Close();
        }

        protected void Button_ShowUserKpi_Click(object sender, EventArgs e)
        {
            SelectedMonth = DropDownList_SelectMonth.SelectedValue;

            //GridView_uMKpiForm.AutoGenerateEditButton = true;
            //GridView_uMKpiForm.ShowHeader = true;

            GridView_uMKpiForm_DataBind();

            //显示页脚KPI权重合计
            //应该在DataBind()时执行......
            //GridView_ShowKpiInfo_BuildFooter();
        }

        protected void GridView_uMKpiForm_DataBind()
        {
            GridView_uMKpiForm.Columns.Clear();
            //GridView_uMKpiForm.Dispose();

            String UserName = DropDownList_UserName.SelectedValue.ToString();

            //
            //Label_DebugMsg.Text = UserName;

            SqlConnection SqlConnection = new SqlConnection("Data Source=192.168.0.241;Initial Catalog=kpi_forms_db;Persist Security Info=True;User ID=sa;Password=My.SA");
            SqlConnection.Open();

            String SelectCommand = "SELECT [id],[UserName],[u_kpi],[u_kpi_std],[u_kpi_comm],[u_kpi_rat],[u_kpi_fx],[uM_kpi_rec],[u_kpi_ref],[u_kpi_done_comm],[u_kpi_conf],[u_kpi_m] FROM [dbo].[u_kpi_table] WHERE UserName IN (SELECT UserName FROM [u_kpi_userInManager] WHERE u_kpi_ins_datetime BETWEEN (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,'" + SelectedMonth + "'), 0)) AND (SELECT DATEADD(ms,-1,DATEADD(mm, DATEDIFF(m,0,'" + SelectedMonth + "')+1, 0))) AND uManagerName='" + User.Identity.Name + "')";

            if(!CheckBox_ShowDetail.Checked)
            {
                SelectCommand += " AND u_kpi_doneconf = '1'";
            }

            if (UserName != "all")
            {
                SelectCommand += " AND UserName = \'" + UserName + "\'";
            }

            SelectCommand += " ORDER BY UserName";

            DataSet UserKpiFormDataSet = new DataSet();

            SqlDataAdapter dataAdapter = new SqlDataAdapter(SelectCommand, SqlConnection);
            dataAdapter.Fill(UserKpiFormDataSet);
            //dataAdapter.Fill(UserKpiFormDataSet, "id");            

            GridView_uMKpiForm.DataSource = UserKpiFormDataSet;

            GridView_uMKpiForm.DataKeyNames = new string[] { "id" };

            GridView_uMKpiForm.AutoGenerateColumns = false;

            BoundField bField;
            bField = new BoundField();
            bField.DataField = "id";
            bField.HeaderText = "编号";
            bField.ReadOnly = true;
            GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "UserName";
            bField.HeaderText = "姓名";
            bField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            //bField.ItemStyle.Width = 20;
            bField.ItemStyle.Wrap = false;
            GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi";
            bField.HeaderText = "KPI明细";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_std";
            bField.HeaderText = "KPI数值/内容";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_comm";
            bField.HeaderText = "KPI说明";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_uMKpiForm.Columns.Add(bField);

            //Cells[5]
            bField = new BoundField();
            bField.DataField = "u_kpi_rat";
            bField.HeaderText = "KPI权重";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_fx";
            bField.HeaderText = "KPI公式";
            bField.HeaderStyle.Wrap = false;
            //bField.HeaderStyle.Width = 240;
            bField.ReadOnly = true;
            GridView_uMKpiForm.Columns.Add(bField);

            //Cells[7]
            bField = new BoundField();
            bField.DataField = "u_kpi_ref";
            bField.HeaderText = "KPI实际数值/内容";
            //bField.HeaderStyle.Width = 120;
            bField.HeaderStyle.Wrap = false;
            //bField.ReadOnly = true;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            GridView_uMKpiForm.Columns.Add(bField);
                        
            bField = new BoundField();
            bField.DataField = "u_kpi_done_comm";
            bField.HeaderText = "完成情况说明";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "uM_kpi_rec";
            bField.HeaderText = "KPI考评得分";
            //bField.ReadOnly = true;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            GridView_uMKpiForm.Columns.Add(bField);

            //bField = new BoundField();
            //bField.DataField = "u_kpi_conf";
            //bField.HeaderText = "KPI考评得分";
            //bField.ReadOnly = true;
            //GridView_uMKpiForm.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_m";
            bField.HeaderText = "KPI考评人";
            bField.ReadOnly = true;
            bField.ItemStyle.Wrap = false;
            GridView_uMKpiForm.Columns.Add(bField);

            CommandField cfEdit = new CommandField();
            cfEdit.ButtonType = ButtonType.Link;
            cfEdit.EditText = "修改";
            cfEdit.ShowEditButton = true;
            cfEdit.ItemStyle.Wrap = false;

            cfEdit.UpdateText = "更新";
            cfEdit.CancelText = "取消";

            GridView_uMKpiForm.Columns.Add(cfEdit);

            //隐藏id列
            GridView_uMKpiForm.Columns[0].Visible = false;

            GridView_uMKpiForm.DataBind();

            dataAdapter.Dispose();
            GridView_uMKpiForm.Dispose();
            SqlConnection.Close();

            //显示页脚合计
            if(GridView_uMKpiForm.Rows.Count > 0)
            {
                GridView_ShowKpiInfo_BuildFooter();
            }            
        }

        protected void GridView_uMKpiForm_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                //命令为修改
                case "edit":
                    {
                        GridViewRow gridViewRow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
                        int index = gridViewRow.RowIndex;
                        GridView_uMKpiForm.EditIndex = index;
                        //GridView_uMKpiForm_DataBind();
                        break;
                    }
            }
        }

        protected void GridView_uMKpiForm_RowCreated(object sender, GridViewRowEventArgs e)
        {
            //Label_DebugMsg.Text = Convert.ToString(GridView_uMKpiForm.Columns.Count);
            //int ColIndex = 5;

            //无效
            //e.Row.Cells[4].Visible = false;

            //Error:
            //Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
            //GridView_uMKpiForm.Rows[0].Cells[4].Visible = false;

            //Error:
            //Object reference not set to an instance of an object.
            //GridView_uMKpiForm.HeaderRow.Cells[1].Visible = false;

            //无效
            //if (e.Row.RowType == DataControlRowType.DataRow ||
            //            e.Row.RowType == DataControlRowType.Header)
            //{
            //    e.Row.Cells[4].Visible = false;
            //}

            //无效
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    e.Row.Cells[4].Visible = false;
            //}

            //Error
            //Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
            //[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index]
            //GridView_uMKpiForm.Columns[ColIndex].Visible = false;

            //无效
            //this.GridView_uMKpiForm.Columns[ColIndex].Visible = false;            
        }

        protected void GridView_uMKpiForm_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //Label_DebugMsg.Text = " GridView_uMKpiForm_RowDataBound?";

            int ColCount = e.Row.Cells.Count;
            //Label_DebugMsg.Text = Convert.ToString(ColCount);

            //GridView_uMKpiForm.Rows[1].Cells[2].Visible = false;

            //无效
            //GridView_uMKpiForm.Rows[1].Cells[5].Text = "TEXT";

            //无效
            //e.Row.Cells[2].Visible = false;

            //无效
            //this.GridView_uMKpiForm.Columns[5].Visible = false;

            //无效
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    GridView_uMKpiForm.Columns[1].Visible = false;
            //}

            //显示页脚合计
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            //    DataRowView totalRows = (System.Data.DataRowView)e.Row.DataItem;
            //    for (int i = 0; i < GridView_UserKpiForm.HeaderRow.Cells.Count; i++)
            //    {
            //        if (GridView_UserKpiForm.HeaderRow.Cells[i].Text.Equals("权重"))
            //        {
            //            e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Center;
            //            _u_kpi_rat += Convert.ToDecimal(totalRows[i].ToString());
            //        }
            //    }
            //}
            //else if (e.Row.RowType == DataControlRowType.Footer)
            //{
            //    e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
            //    e.Row.Cells[2].Text = "合计：";

            //    for (int i = 0; i < GridView_UserKpiForm.HeaderRow.Cells.Count; i++)
            //    {
            //        if (GridView_UserKpiForm.HeaderRow.Cells[i].Text.Equals("权重"))
            //        {
            //            //如果当前权重合计>=100，则阻止用户继续录入
            //            //if (_u_kpi_rat > 100)
            //            //{
            //            //    Button_Cf_Kpi_info.Visible = false;
            //            //    Button_UserConf.Visible = false;
            //            //    Label_ErrorMsg.ForeColor = Color.Red;
            //            //    Label_ErrorMsg.Text = "<br /><br />权重合计值已经等于100，无法继续录入以及确认KPI信息！如需继续，请修改已录入的KPI信息。<br /><br />";
            //            //    Label_ErrorMsg.Visible = true;
            //            //}
            //            //else
            //            //{
            //            //    Button_Cf_Kpi_info.Visible = true;
            //            //    Button_UserConf.Visible = true;

            //            //    Label_ErrorMsg.Visible = false;
            //            //}

            //            e.Row.Cells[i].Text = _u_kpi_rat.ToString();
            //            e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Center;
            //        }
            //    }
            //}
        }

        protected void GridView_uMKpiForm_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //Set the edit index.
            GridView_uMKpiForm.EditIndex = e.NewEditIndex;

            //Bind data to the GridView control.
            GridView_uMKpiForm_DataBind();
        }

        protected void GridView_uMKpiForm_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            //Reset the edit index.
            GridView_uMKpiForm.EditIndex = -1;

            //Bind data to the GridView control.
            GridView_uMKpiForm_DataBind();
        }

        protected void GridView_uMKpiForm_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Label_ErrorMsg.Visible = false;

            //参考资料
            //http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.gridview.rowupdating(v=vs.110).aspx            

            //DataKeys取值
            String id = GridView_uMKpiForm.DataKeys[e.RowIndex]["id"].ToString();

            //非编辑状态的单元格取值
            String u_kpi_rat = GridView_uMKpiForm.Rows[e.RowIndex].Cells[5].Text;

            //编辑状态的单元格（即TextBox）取值            
            String u_kpi_ref = ((TextBox)GridView_uMKpiForm.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
            //String u_kpi_ref = GridView_uMKpiForm.Rows[e.RowIndex].Cells[7].Text;

            //考评分数如果输入小数，将会抛出FormatException
            try
            {
                String uM_kpi_rec = ((TextBox)GridView_uMKpiForm.Rows[e.RowIndex].Cells[8].Controls[0]).Text;

                if (Int32.Parse(uM_kpi_rec) > Int32.Parse(u_kpi_rat))
                {
                    Label_ErrorMsg.ForeColor = Color.Red;
                    Label_ErrorMsg.Text = "您输入的考评分数不应大于该项KPI权重。";
                    Label_ErrorMsg.Visible = true;

                    //如果考评分大于该项权重，则考评分等于权重
                    uM_kpi_rec = u_kpi_rat;
                }

                GridView_uMKpiForm_RowUpdate(id, u_kpi_ref, uM_kpi_rec, User.Identity.Name);
            }
            catch (FormatException uM_kpi_rec_e)
            {
                Label_ErrorMsg.ForeColor = Color.Red;
                Label_ErrorMsg.Text = "考评分数请输入整数数字。";
                Label_ErrorMsg.Visible = true;
            }

            //Set the edit index.
            GridView_uMKpiForm.EditIndex = -1;

            //Bind data to the GridView control.
            GridView_uMKpiForm_DataBind();
        }

        protected void GridView_uMKpiForm_RowUpdate(String id, String u_kpi_ref, String uM_kpi_rec, String u_kpi_m)
        {
            //调试信息
            //Label_DebugMsg.Text = "id:" + id + ", u_kpi_ref:" + u_kpi_ref + ", uM_kpi_rec:" + uM_kpi_rec;
            //Label_DebugMsg.Visible = true;

            SqlConnection SqlConnection = new SqlConnection("Data Source=192.168.0.241;Initial Catalog=kpi_forms_db;Persist Security Info=True;User ID=sa;Password=My.SA");
            SqlConnection.Open();

            SqlCommand updateCommand = new SqlCommand("UPDATE [dbo].[u_kpi_table] SET [u_kpi_ref] = @u_kpi_ref, [u_kpi_m] = @u_kpi_m, [uM_kpi_rec] = @uM_kpi_rec, [u_mKpi_conf_datetime] = @u_mKpi_conf_datetime WHERE id=@id", SqlConnection);
            updateCommand.CommandType = CommandType.Text;

            updateCommand.Parameters.Add("@id", SqlDbType.UniqueIdentifier);
            updateCommand.Parameters.Add("@u_kpi_ref", SqlDbType.VarChar, 8000);
            updateCommand.Parameters.Add("@uM_kpi_rec", SqlDbType.Int, 2);
            updateCommand.Parameters.Add("@u_kpi_m", SqlDbType.NVarChar, 4);
            updateCommand.Parameters.Add("@u_mKpi_conf_datetime", SqlDbType.DateTime);

            updateCommand.Parameters["@id"].Value = new System.Guid(id);
            updateCommand.Parameters["@u_kpi_ref"].Value = u_kpi_ref;
            updateCommand.Parameters["@uM_kpi_rec"].Value = Int32.Parse(uM_kpi_rec);
            updateCommand.Parameters["@u_kpi_m"].Value = u_kpi_m;
            updateCommand.Parameters["@u_mKpi_conf_datetime"].Value = DateTime.Now;

            try
            {
                updateCommand.ExecuteNonQuery();
            }
            catch (SqlException se)
            {
                Label_ErrorMsg.Text = se.Message;
                Label_ErrorMsg.Visible = true;
            }

            SqlConnection.Close();
        }

        //构建页脚合计
        protected void GridView_ShowKpiInfo_BuildFooter()
        {
            //Label_DebugMsg.Text = GridView_ShowKpiInfo.HeaderRow.Cells.Count.ToString();
            //Label_DebugMsg.Text = GridView_ShowKpiInfo.Rows.Count.ToString();

            if (GridView_uMKpiForm.Rows.Count > 0)
            {
                //KPI权重合计
                Decimal _u_kpi_rat = 0m;
                //KPI实际值合计
                Decimal _u_kpi_ref = 0m;
                //KPI考评分合计
                Decimal _uM_kpi_rec = 0m;

                for (int i = 0; i < GridView_uMKpiForm.Rows.Count; i++)
                {
                    if (GridView_uMKpiForm.Rows[i].RowType == DataControlRowType.DataRow)
                    {
                        _u_kpi_rat += Convert.ToDecimal(GridView_uMKpiForm.Rows[i].Cells[5].Text);
                        _u_kpi_ref += Convert.ToDecimal(GridView_uMKpiForm.Rows[i].Cells[7].Text);
                        _uM_kpi_rec += Convert.ToDecimal(GridView_uMKpiForm.Rows[i].Cells[9].Text);
                    }
                }

                GridView_uMKpiForm.FooterRow.Cells[1].Wrap = false;
                GridView_uMKpiForm.FooterRow.Cells[1].HorizontalAlign = HorizontalAlign.Center;
                GridView_uMKpiForm.FooterRow.Cells[1].Text = "合计：";
                GridView_uMKpiForm.FooterRow.Cells[5].HorizontalAlign = HorizontalAlign.Center;
                GridView_uMKpiForm.FooterRow.Cells[5].Text = _u_kpi_rat.ToString();
                GridView_uMKpiForm.FooterRow.Cells[7].HorizontalAlign = HorizontalAlign.Center;
                GridView_uMKpiForm.FooterRow.Cells[7].Text = _u_kpi_ref.ToString();
                GridView_uMKpiForm.FooterRow.Cells[9].HorizontalAlign = HorizontalAlign.Center;
                GridView_uMKpiForm.FooterRow.Cells[9].Text = _uM_kpi_rec.ToString();
            }
        }
    }
}